from typing import Optional

from fastapi import APIRouter
from fastapi_amis_admin.globals.deps import AsyncSess, SyncSess
from fastapi_amis_admin.models import Field

from backend.apps.common import PageParams, PageResult, ApiResult
from .models import SysMenu, MenuQueryParams, SysMenuDTO
from .service import MenuService as menuService
router = APIRouter()



@router.post("/page")
def page(params: MenuQueryParams, sess: SyncSess):
    return menuService.page(params, sess)

@router.post("/list")
def page(sess: SyncSess):
    list = menuService.list(sess)
    return ApiResult(data=list)

@router.get("/detail", response_model=ApiResult)
def detail(id: int, sess: SyncSess):
    return ApiResult(data=menuService.detail(id, sess))

@router.post("/save")
def save(sess: SyncSess, data: SysMenuDTO):
    menuService.save(sess, data)
    return ApiResult()


@router.put("/update")
def update(data: SysMenu, sess: SyncSess):
    menuService.update(data, sess)
    return ApiResult()


@router.delete("/delete")
def delete(id: int, sess: SyncSess):
    menuService.delete(id, sess)
    return ApiResult()
